package com.imy.touch;

import android.os.SystemClock;
import android.view.MotionEvent;

import com.imy.touch.bean.GesturePoint;
import com.imy.touch.constant.MotionEventExt;
import com.imy.touch.interfaces.GestureInterface;
import com.imy.touch.service.GestureManagerService;

public final class GestureManager {

  private static GestureManager gCore = new GestureManager();

  public static GestureManager get() {
    return gCore;
  }

  public void clicked(float x, float y, int id) {
    GesturePoint build = GesturePoint.Builder.builder(x, y, MotionEventExt.MOTION_CLICKED, id, SystemClock.uptimeMillis())
        .build();
    getService().onClicked(build);
  }
  public void down(float x, float y, int id) {
    GesturePoint build = GesturePoint.Builder.builder(x, y, MotionEvent.ACTION_DOWN, id, SystemClock.uptimeMillis())
        .build();
    getService().onDown(build);
  }

  public void up(float x,float y,int id){
    GesturePoint build = GesturePoint.Builder.builder(x, y, MotionEvent.ACTION_UP, id, SystemClock.uptimeMillis())
        .build();
    getService().onUp(build);
  }
  public void move(float x,float y,int id){
    GesturePoint build = GesturePoint.Builder.builder(x, y, MotionEvent.ACTION_MOVE, id, SystemClock.uptimeMillis())
        .build();
    getService().onMove(build);
  }

  private GestureInterface getService() {
    return GestureManagerService.get();
  }

  public void swipe(int startX, int startY, int endX, int endY, int step, int time, int id) {
    GesturePoint start = GesturePoint.Builder
        .builder(startX, startY, MotionEventExt.MOTION_SWIPE_START, id,
        SystemClock.uptimeMillis())
        .build();
    GesturePoint end = GesturePoint.Builder
        .builder(endX, endY, MotionEventExt.MOTION_SWIPE_END, id,
        SystemClock.uptimeMillis())
        .build();
    getService().swipe(start,end,step,time);
  }

  public void longClicked(int x, int y, int id) {
    GesturePoint build = GesturePoint.Builder.builder(x, y, MotionEventExt.MOTION_LONG_CLICKED, id,
        SystemClock.uptimeMillis())
        .build();
    getService().longClicked(build);
  }
}
